<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件号" prop="certNo">
        <el-input
          v-model="queryParams.certNo"
          placeholder="请输入证件号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门" prop="deptId">
        <tree-select v-model="queryParams.deptId" :options="departmentAllListData"
                     placeholder="选择部门"
                     style="width: 200px"/>
      </el-form-item>

      <el-form-item label="账单月份" prop="monthBilling">
        <el-date-picker clearable size="small" style="width: 200px"
                        v-model="queryParams.monthBilling"
                        type="month"
                        value-format="yyyyMM"
                        placeholder="选择账单月份">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['hr:scscBillDetail:export']"
        >导出
        </el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="scscBillDetailList">
      <el-table-column label="姓名" align="center" prop="name"/>
      <el-table-column label="证件号" align="center" prop="certNo"  width="170"/>
      <el-table-column label="部门" align="center" prop="deptName"  width="180"/>
      <el-table-column label="账单月份" align="center" prop="monthBilling" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.monthBilling }}</span>
        </template>
      </el-table-column>
      <el-table-column label="社保公积金企业小计" align="center" prop="expEnterprise" width="160"/>
      <el-table-column label="社保公积金个人小计" align="center" prop="expEmployee" width="160"/>
      <el-table-column label="服务费" align="center" prop="expService"/>
      <el-table-column label="费用总计" align="center" prop="expTotal"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
  import TreeSelect from '@riophae/vue-treeselect'
  import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  import { listScscBillDetail } from '@/api/hr/scscBillDetail'
  import myRequest from '@/utils/myRequest'
  import commonMixins from '@/mixins/common'

  export default {
    name: 'scscBillDetail',
    mixins: [commonMixins],
    components: { TreeSelect },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 总条数
        total: 0,
        // 社保对账单明细表格数据
        scscBillDetailList: [],
        // 弹出层标题
        title: '',
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          pid: undefined,
          name: undefined,
          certNo: undefined,
          deptId: undefined,
          monthExpense: undefined,
          monthBilling: undefined
        },
        departmentAllListData: []
      }
    },
    created() {
      let pid = this.$route.query.pid
      if (pid) {
        this.queryParams.pid = pid
      }
      this.getList()
      this.getDepartmentAllListData()
    },
    methods: {
      /** 查询社保对账单明细列表 */
      getList() {
        this.loading = true
        listScscBillDetail(this.queryParams).then(response => {
          this.scscBillDetailList = response.rows
          this.total = response.total
          this.loading = false
        })
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm('queryForm')
        this.handleQuery()
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams
        this.$confirm('是否确认导出所有社保对账单明细数据项?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async() => {
          let response = await myRequest({
            url: '/hr/scscBillDetail/export',
            method: 'get',
            params: queryParams,
            responseType: 'blob'
          })
          this.downloadFile(response)
        })
      },
      /** 获取部门下拉树 **/
      async getDepartmentAllListData() { // 获取所有数据
        try {
          await this.$store.dispatch('department/GetDepartmentList', {
            request: true,
            showChargedOnly: true
          }).then(response => {
            this.departmentAllListData = response.data
          })
        } catch (error) {
          this.$notify.error({
            title: '错误',
            message: error.message
          })
        }
      }
    }
  }
</script>
